package com.qf.iprate.controller;

import com.qf.iprate.utils.Constants;
import com.qf.iprate.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping("/add")
    public R addIpToBlackList(String ip){

        String key = Constants.IP_BLACKLIST_KEY;
        redisTemplate.opsForSet().add(key,ip);

        return R.ok();
    }


    @GetMapping("/test1")
    public R test1(HttpServletRequest request){
        String ip = request.getRemoteAddr();
        log.info("ip地址为：{}",ip);

        return R.ok(ip);
    }

}
